// ==========================================================================
// GFast自动生成controller操作代码。
// 生成日期：2024-06-18 17:14:29
// 生成路径: internal/app/app/controller/app_news.go
// 生成人：gfast
// desc:文章
// company:云南奇讯科技有限公司
// ==========================================================================

package controller

import (
	"context"
	"errors"

	"github.com/tiger1103/gfast/v3/api/v1/app"
	"github.com/tiger1103/gfast/v3/internal/app/app/service"
	systemController "github.com/tiger1103/gfast/v3/internal/app/system/controller"
	systemService "github.com/tiger1103/gfast/v3/internal/app/system/service"
)

type appNewsController struct {
	systemController.BaseController
}

var AppNews = new(appNewsController)

// List 列表
func (c *appNewsController) List(ctx context.Context, req *app.AppNewsSearchReq) (res *app.AppNewsSearchRes, err error) {
	res = new(app.AppNewsSearchRes)
	res.AppNewsSearchRes, err = service.AppNews().List(ctx, &req.AppNewsSearchReq)
	return
}

// LinkedAppNewsDataSearch 相关连表查询数据
func (c *appNewsController) LinkedAppNewsDataSearch(ctx context.Context, req *app.LinkedAppNewsDataSearchReq) (res *app.LinkedAppNewsDataSearchRes, err error) {
	if !systemService.SysUser().AccessRule(ctx, systemService.Context().GetUserId(ctx), "api/v1/app/appNews/list") {
		err = errors.New("没有访问权限")
		return
	}

	res = new(app.LinkedAppNewsDataSearchRes)
	res.LinkedAppNewsDataSearchRes, err = service.AppNews().LinkedAppNewsDataSearch(ctx)
	return
}

// Get 获取文章
func (c *appNewsController) Get(ctx context.Context, req *app.AppNewsGetReq) (res *app.AppNewsGetRes, err error) {
	res = new(app.AppNewsGetRes)
	res.AppNewsInfoRes, err = service.AppNews().GetById(ctx, req.Id)
	return
}

// Add 添加文章
func (c *appNewsController) Add(ctx context.Context, req *app.AppNewsAddReq) (res *app.AppNewsAddRes, err error) {
	err = service.AppNews().Add(ctx, req.AppNewsAddReq)
	return
}

// Edit 修改文章
func (c *appNewsController) Edit(ctx context.Context, req *app.AppNewsEditReq) (res *app.AppNewsEditRes, err error) {
	err = service.AppNews().Edit(ctx, req.AppNewsEditReq)
	return
}

// Delete 删除文章
func (c *appNewsController) Delete(ctx context.Context, req *app.AppNewsDeleteReq) (res *app.AppNewsDeleteRes, err error) {
	err = service.AppNews().Delete(ctx, req.Ids)
	return
}
